<%@page import="com.mbbcpa.util.StringUtils"%>
<%@page import="com.mbbcpa.reference.ReferenceModel"%>
<%@ page import = "java.util.Map" %>
<%@ page import = "java.util.Vector" %>
<%@ page import = "java.util.ArrayList" %>
<%@ page import = "com.mbbcpa.util.Constants" %>
<%@ page import = "com.mbbcpa.security.dao.*" %>

<%
Map map = null;
Vector vRef = null;
Vector vRefList = null;
String sMessage = StringUtils.NullSafe((String) request.getAttribute("sMessage")) ;

if (request.getAttribute("map") != null){
	map = (Map) request.getAttribute("map");
	vRef = (Vector) map.get("vRef");
	vRefList = (Vector) map.get("vRefList");
}




ArrayList secGroupAccessList = (ArrayList) session.getAttribute(Constants.LOGON_ACCESS_LIST);
SecUserDao oSecUserDao = (SecUserDao) session.getAttribute(Constants.LOGGED_USER);
String sUserName = oSecUserDao.getUserName();
String lastLogonDateTime = (String) session.getAttribute(Constants.LAST_LOGON_DATETIME);

String selected = "refman";
int iManualCP = 0;	//MAN000
int iSecMan = 0;	//SEC000
int iFAQ = 0;		//FAQ000
int iExempt = 0;	//EXE000
int iChangePW = 0;	//CPW000
int iRefMan = 0;	//RFM000
int iUserGuid = 0;	//USG000
	

for(int i=0;i<secGroupAccessList.size();i++){
	SecAccessDao secaccessDao = (SecAccessDao)secGroupAccessList.get(i);
	String strModuleCode  = secaccessDao.getModuleCode();
	if(strModuleCode.equals("MAN000"))
		iManualCP = 1;
	if(strModuleCode.equals("SEC000"))
		iSecMan = 1;
	if(strModuleCode.equals("FAQ000"))
		iFAQ = 1;
	if(strModuleCode.equals("EXE000"))
		iExempt = 1;
	if(strModuleCode.equals("CPW000"))
		iChangePW = 1;
	if(strModuleCode.equals("RFM000"))
		iRefMan = 1;
	if(strModuleCode.equals("USG000"))
		iUserGuid = 1;
}
%>
<link href="resource/style.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
	function AddReference(){
		var frm = document.ReferenceForm;
		if (frm.refname.value == ""){
			alert("Reference Name is Required.");
			frm.refname.focus();
			return;
		}
		if (frm.reftype.value == ""){
			alert("Reference Type is Required.");
			frm.reftype.focus();
			return;
		}else{
			if (frm.reftype.value == "VALUE" && frm.refvalue.value == ""){
				alert("Reference Value is Required.");
				frm.refvalue.focus();
				return;
			}
		}
		
		frm.action = "ReferenceManagement.do?dispatch=AddReference";
		frm.submit();
	}
	function AddMode(){
		document.getElementById("tblAdd").style.display = "";
		document.getElementById("rowAdd").style.display = "none";
	}
	
	function deleteRef(refId,refName){
		var frm = document.ReferenceForm;
		var msg = "Confirm Delete of " + refName;
		
		if (confirm(msg)){
			frm.action = 'ReferenceManagement.do?dispatch=deleteRef&refId=' + refId + '&refName=' + refName;
			frm.submit();	
		}
		
	}
</script>
	<script type="text/javascript">
	    window.history.forward();
	    function noBack() { window.history.forward(); }
	</script>
<style type="text/css"></style></head>

<body class="home" onload="noBack();" onpageshow="if (event.persisted) noBack();" onunload="">
	<a name="top"></a>
<!-- Header -->
<%@ include file="../common/Header.jsp" %>	
<!-- End Header -->
<form name="ReferenceForm" method="post">	
	<div id="bgWrapper">
		<div id="container">

			<div id="titleBar">
				<ul class="topBar">
					<li class="goBackBt"><a href="<%=request.getContextPath()%>/CheckUserLogon.do?dispatch=homePage"></a></li>
					<li>
					  <h1>Reference Management</h1></li>
				</ul>
			</div>

			<div id="fullcontent">
				

<!-- Root Navigation -->
<%@ include file="../common/RootNavigation.jsp" %>	
<!-- End Root Navigation -->

<div id="contentRightIn">
	<table align="center" class="tblDetails" width=90% border="0" rules="cols">
			<thead class="th1">
				<tr>
					<th colspan="5">
						<div class="sectionTableTitle">
							<h3>Reference List Setup</h3>
						</div>
					</th>
			</thead>
			<tr class="even" style="border: thin solid">
				<td width="5%" class="center_note">No</td>
				<td width="25%" class="center_note">Reference Name</td>
				<td width="25%" class="center_note">Reference Type</td>
				<td width="25%" class="center_note">Reference Value</td>
				<td width="20%" class="center_note">&nbsp;</td>
			</tr>
			<% for(int j = 0; j < vRef.size(); j++){
				ReferenceModel oRefModel = (ReferenceModel) vRef.elementAt(j);	
				String rowclass = ((j % 2) == 0 ? "even":"odd");
			%>
			<tr class="<%=rowclass%>" >
				<td class="center_note"><%=j+1%></td>
				<%if (oRefModel.get_ref_type().equalsIgnoreCase("LIST")) {%>
					<td class="center_note"><a href="<%=request.getContextPath()%>/ReferenceManagement.do?dispatch=showRefList&refName=<%=oRefModel.get_ref_name()%>"><%=oRefModel.get_ref_name()%></a></td>
				<%}else{ %>
					<td class="center_note"><%=oRefModel.get_ref_name()%></td>
				<%}%>
				<td class="center_note"><%=oRefModel.get_ref_type()%></td>
				<td class="center_note"><%=oRefModel.get_ref_value()%></td>
				<td class="center_note">
					<a href="<%=request.getContextPath()%>/ReferenceManagement.do?dispatch=editRef&refId=<%=oRefModel.get_ref_id()%>">Edit</a>&nbsp;&nbsp;&nbsp;
					<a href="javascript:deleteRef('<%=oRefModel.get_ref_id()%>','<%=oRefModel.get_ref_name()%>');">Delete</a>
					</td>
			</tr>
			<%} %>
			<tr align="center" id="rowAdd">
				<td width="40%" class="center_note" colspan="5"><input class="inputButton" type="button" name="addmode" value="Add Reference" onClick="JavaScript:AddMode();"><%=sMessage%></td>
			</tr>	
		</table>
		<br>
		<table align="center" class="tblInput" width=90% border="0" rules="cols" id="tblAdd" style="display:none">
			<thead class="th1">
				<tr>
					<th colspan="5">
						<div class="sectionTableTitle">
							<h3>Add Reference</h3>
						</div>
					</th>
			</thead>
			<tr>
				<td width="25%" class="inputStyle">Reference Name:</td>
				<td width="75%" class="inputStyle"><input class="inputStyle" type="text" name="refname" value=""></td>
			</tr>
			<tr>
				<td class="inputStyle">Reference Value:</td>
				<td class="inputStyle"><input class="inputStyle" type="text" name="refvalue" value=""></td>
			</tr>
			<tr>
				<td class="inputStyle">Reference Type:</td>
				<td class="inputStyle">
					<select name="reftype" class="inputStyle">
						<option value="" selected>- Please Select -</option>
						<option value="LIST">List</option>
						<option value="VALUE">Value</option>
					</select>
				</td>
			</tr>
			<tr align="center">
				<td width="40%" class="center_note" colspan="2"><input class="inputButton" type="button" name="add" value="Add" onClick="JavaScript:AddReference();"><%=sMessage%></td>
			</tr>
		</table>
</div>
</div>
<!-- Footer -->
<%@ include file="../common/Footer.jsp" %>	
<!-- End Footer -->

		</div>
	</div>

</form>



